package com.ftg.learn.annotationforme;

import com.ftg.learn.annotationforme.entity.ShopProductEntity;
import com.ftg.learn.annotationforme.mapper.ShopProductMapper;
import org.apache.ibatis.io.Resources;
import org.apache.ibatis.session.SqlSession;
import org.apache.ibatis.session.SqlSessionFactory;
import org.apache.ibatis.session.SqlSessionFactoryBuilder;

import javax.sql.DataSource;
import java.io.IOException;
import java.io.Reader;
import java.util.List;

/**
 * @author 布衣
 */
public class Demo {

    public static void main(String[] args) {
        String path = "annotation/configuration.xml";
        Reader resourceAsReader = null;

        try{
            resourceAsReader =  Resources.getResourceAsReader(path);
            SqlSessionFactoryBuilder builder = new SqlSessionFactoryBuilder();
            SqlSessionFactory factory = builder.build(resourceAsReader);

            SqlSession sqlSession = factory.openSession();

            ShopProductMapper mapper = sqlSession.getMapper(ShopProductMapper.class);
            List<ShopProductEntity> shopProductEntities = mapper.listByProName("康");

            System.out.println("==>"+shopProductEntities);
        }catch (IOException e){

        }

    }

}
